<template>

  <div>
    <div >
      <el-breadcrumb separator="/">
        <!--     <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>-->
        <!--     <el-breadcrumb-item><a href="/">活动管理</a></el-breadcrumb-item>-->
        <el-breadcrumb-item>采购管理</el-breadcrumb-item>
        <el-breadcrumb-item>采购车管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div style="float: left;margin-top: 8px;margin-bottom: 8px">
      <el-button type="primary" @click="_submitPurchase">提交采购单</el-button>
    </div>


    <div style="margin-top: 20px">

      <el-table
        :data="getPage"
        border
        height="500"
        ref="multipleTable"
        style="width: 100%"

        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>

        <el-table-column v-for="item in columnName" :key="item.id" :label="item.label" >
          <template slot-scope="scope">
            <span>{{scope.row[item.prop]}}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
            <el-button @click="_edit(scope.row)" type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>


    </div>
  </div>

</template>

<script>

  export default {

    mounted(){
      this._page();
    },
    components:{
    },
    name: "Home",
    data(){
      return {

        currentPage:1, //初始页
        pageSize:10,    //    每页的数据
        total:0,    //    每页的数据
        getPage:[],

        selectIds:[],
        columnName:[
          {prop:"productName",label:"商品名称",width:"120",fixed:true},
          {prop:"categoryName",label:"类别",width:"120"},
          {prop:"model",label:"规格型号",width:"120"},
          {prop:"price",label:"价格",width:"120"},
          {prop:"supplier",label:"供应商",width:"120"},
          {prop:"ctime",label:"添加时间",width:"120"},
          {prop:"num",label:"采购数量",width:"120"},
          {prop:"name",label:"添加人",width:"120"},
        ],
      }
    },
    methods:{
      handleClick(data){
        console.log(data);
      },

      handleSizeChange(val) {
        this.pageSize=val;
        this._page();
      },
      handleCurrentChange(val) {
        this.currentPage=val;
        this._page();
      },

      _page(){
        this.$http.post('/t_purchase_cart/page_vo?rows='+this.pageSize+'&page='+this.currentPage,{}).then(res=>{
          let data= res.data.data;
          this.getPage=data.records;
          console.log('----------------data',data)
          console.log('-----------------',data.total)
          this.total=data.total;
        }).catch(err=>{
          console.log(err)
        });
      },

      _submitPurchase(){
        if (this.selectIds.length==0) {
          this.$message({
            message: '请选择',
            type: 'warning'
          });
          return false;
        }else{

          this.$http.post('/t_purchase/add_purchase_order?ids='+this.selectIds).then(res=>{
                  this.$message({
                    type: 'success',
                    message: '添加成功!'
                  });
                 this._page();
          }).catch(err=>{
            console.log(err)
          });


        }
      },


      _edit(row){
        console.log(row);
        this.$refs.goodsCategoryEditRef._open(row);
      },

      _add(){
        this.$refs.goodsCategoryEditRef._open();
      },

      handleSelectionChange(val) {
        let length = val.length;
        let ids=[];
        for(let i=0;i<length;i++){
          ids[i]=val[i].id;
        }
      this.selectIds=ids;
      }
    },
  }
</script>

<style scoped>

</style>
